﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

using LIM.model;

namespace LIM.controller
{
    public class CRM_NhatKyLienLacController : BaseController
    {
        public CRM_NhatKyLienLacController() { }
        public CRM_NhatKyLienLacController(LIMS_Entities LIMS_Entities)
        {
            this.LIMS_Entities = LIMS_Entities;
        }

        public object LoadNhatKyLienHe(int RowIDKhachHang = 0, int RowIDLienHe = 0, string ChuDe = "")
        {
            return LIMS_Entities.tbl_CRM_NhatKyLienLac.Where(p => (RowIDLienHe!=0? p.RowIDLienHe == RowIDLienHe:true) 
                && (RowIDKhachHang!=0? p.RowIDKhachHang == RowIDKhachHang:true) 
                && (ChuDe!=""? p.ChuDe == ChuDe :true)
                ).OrderByDescending(p => p.NgayTao).ToList().Select(o => new
            {
                NgayTao = o.NgayTao,
                HinhThucLienLac = LIMS_Entities.tbl_DanhMuc_HeThong.Where(d => d.MaDanhMuc == o.MaHinhThuc).OrderByDescending(p => p.NgayTao).FirstOrDefault().TenGoi,
                NoiDung = o.NoiDung,
                KetQua = o.KetQua,
                NguoiTao = LIMS_Entities.tbl_SYS_Users.Where(p => p.UserName == o.NguoiTao).FirstOrDefault(),
            }).ToList();
        }
        
    }
}
